#!/usr/bin/python3
# -*- coding:utf-8 -*-
""""
   @Author: 即将拥有人鱼线的yjw
   @Time: 2023/7/21 9:46
   @File: sqlChange.py
   @desc:
"""
import re


class sqlChange:
    def __init__(self,sql):
        self.sql = sql

    def remove_time(self):
        sql_list = re.split(r"(?i)values",self.sql)
        keys = sql_list[0].lower().split(',')
        keys = [key.strip() for key in keys]
        values =[value.strip() for value in sql_list[1].split(',') if value.strip() != '']
        index = [i for i in range(len(keys)) if "_time" in keys[i]]
        print(values)
        print(keys)
        print(index)
        for i in range(len(index)):
            print(i)
            keys.pop(index[i]-i)
            values.pop(index[i]-i)
            print(keys)
            print(values)
        key_result = ",".join(keys)
        value_result = ",".join([value if value != '' else "''" for value in values])
        if len(keys) in index:
            key_result = +")"
            value_result = +");"
        print(key_result+' values '+value_result)
        return key_result+' values '+value_result

if __name__ == '__main__':
    sql = "INSERT INTO HSAMLWL.AMLWL_BLACKLIST_RELATION (INNER_CLIENT_ID,INIT_DATE,CLIENT_ID,CLIENT_NAME,CLIENT_TYPE,ID_TYPE,ID_NO,FUND_CLIENT_SRC_CHN,CLIENT_STATUS,LIST_TYPE,CREATE_DATE,ISSUE_INSTITUTION,FILTER_MODE,OPERATOR_CODE,OPERATE_DATE,LIST_AUDIT_STATUS,AUDIT_REASON,LIST_DATA_SOURCE,LIST_MATCH_MODE,MATCH_RULE,MATCH_RULE_DESC,REMARKS,RELATION_TYPE_LIST,SERIAL_NO,RELATION_NO,RELATION_NAME,RELATION_TYPE,EXEC_STRT_TIME,EXEC_END_TIME,IS_HIGH_LIGHT,DISTANCE_VALUE,PROCESS_INSTANCE_ID,PROCESS_STATUS,PROCESS_BEGIN_DATE,PROCESS_END_DATE) VALUES ('600001106101',20230424,'600001106101','测试机构关联人','1','27','532321198403215066',' ',' ','01',20230201,' ','0','admin',20230317,'1',' ','0','0','0,2','名称,证件号码','2','0','B000000010802','2|532321198403215066','法人4802','2',TIMESTAMP '2023-02-01 15:39:47.000000',TIMESTAMP '2023-03-17 14:23:45.000000','1',NULL,'7631400','2',20230201,0);"
    print(sql.lower())
    sql_change = sqlChange(sql)
    sql_change.remove_time()



